package com.um.jdy.platform.shop.service.Impl;

import com.um.jdy.common.shop.dao.GoodsCategoryDao;
import com.um.jdy.common.shop.entity.po.GoodsCategory;
import com.um.jdy.platform.shop.entity.vo.GoodsCategoryTreeNode;
import com.um.jdy.platform.shop.service.GoodsCategoryTreeService;
import com.um.springboot.starter.orm.service.TreeServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
@Slf4j
public class GoodsCategoryTreeServiceImpl extends TreeServiceImpl<GoodsCategoryDao, GoodsCategory, GoodsCategoryTreeNode> implements GoodsCategoryTreeService {

    /**
     * 查询树结构
     * @param parentId
     * @return
     */
    @Override
    public List<GoodsCategoryTreeNode> getTree(String parentId) {
        List<GoodsCategory> listNode = dao.getList(new String[]{}, new Object[]{}, new String[]{dao.getTableName()+"_parent_id","sort_no"}, new String[]{"asc","asc"});
        GoodsCategory rootNode = dao.getRow("0");
        listNode.add(rootNode);

        List<GoodsCategoryTreeNode> list = toTreeNodeList(listNode,nodeClass);
        GoodsCategoryTreeNode node = listToTreeNode(parentId,list);

        List<GoodsCategoryTreeNode> treeNodes = new ArrayList<>();
        treeNodes.add(node);
        return treeNodes;
    }

}
